<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>文件列表页面</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="/static/css/font.css">
        <link rel="stylesheet" href="/static/css/xadmin.css">
        <script src="/static/js/jquery.min.js" charset="utf-8"></script>
        <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="/static/js/xadmin.js"></script>
    </head>
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">网盘管理</a>
            <a>
              <cite>文件管理</cite>
            </a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <form class="layui-form layui-col-space5" id="form" action="file/list">
                         <div class="layui-card-header">
                           <!-- <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
                         <div class="layui-btn" onclick="createDownLoadLink()"><i class="layui-icon"></i>生成链接</div>
                         </div>
                         <div class="layui-card-body ">
                            <table class="layui-table layui-form">
                              <thead>
                                <tr>
                                  <th>
                                    <input type="checkbox" name=""  lay-skin="primary">
                                  </th>
                                  <th>文件编码</th>
                                  <th>文件名称</th>
                                  <th>文件存储路径</th>
                                  <th>文件类型</th>
                              </thead>
                              <tbody>
                                <tr th:each="file:${pageInfo.list}">
                                  <td>
                                    <input type="checkbox"  th:name="${file.id}"  lay-skin="primary">
                                  </td>
                                  <td th:text="${file.fileCode}"></td>
                                  <td th:text="${file.fileName}"></td>
                                  <td th:text="${file.filePath}"></td>
                                  <td th:text="${file.fileType}"></td>
                                </tr>
                              </tbody>
                            </table>
                        </div>

                            <input type="hidden" id="pageTotal" th:value="${pageInfo.total}"/>
                            <input type="hidden" id="pageNum"   th:value="${pageInfo.pageNum}" name = "pageNum"/>
                            <input type="hidden" id="pageSize"   th:value="${pageInfo.pageSize}" name = "pageSize"/>
                            <center id="mylayPage" >

                            </center>
                        </form>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>

        function search(){
            $("#pageNum").val(1);
            $("#form").submit();
        }

        layui.use('laypage', function(){
            var laypage = layui.laypage;
            laypage.render({
                 elem: 'mylayPage'
                ,count: $("#pageTotal").val()
                ,limit: $("#pageSize").val()
                ,limits:[5,10,15,20,30]
                ,curr :$("#pageNum").val()
                ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                ,
                jump: function(obj, first){

                    if(!first){
                        $("#pageNum").val(obj.curr);
                        $("#pageSize").val(obj.limit);
                        $("#form").submit();
                    }
                }
            });
        });

      layui.use(['laydate','form'], function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
        });
      });


      /**
       * 创建下载链接
       */
      function createDownLoadLink(){
          var checkedFiles =  $("input[type='checkbox']:checked");
          var fileIds = "";
          for(var i = 0 ;i < checkedFiles.length ; i ++){
              if(fileIds == ""){
                  fileIds = $(checkedFiles[i]).attr("name");
              }else{
                  fileIds += ","+$(checkedFiles[i]).attr("name");
              }
          }
          xadmin.open('创建下载链接','/file/link?fileIds='+fileIds);
      }


    </script>
</html>